﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO; 

namespace DupeKill.Core.Reporting
{
    public class XmlReportFileSetLoader
    {

        public IEnumerable<FileSet> LoadAll(string reportFile)
        {
            XmlDocument document = new XmlDocument();
            document.Load(reportFile);

            foreach (XmlNode fileSetNode in document.FirstChild.ChildNodes)
            {
                FileSet fileSet = new FileSet(); 

                foreach (XmlNode fileNode in fileSetNode.SelectNodes("file"))
                {
                    string fileName = fileNode.InnerText;
                    if (File.Exists(fileName))
                    {
                        fileSet.Add(new FileInformation(fileName, new FileInfo(fileName).Length));
                    }
                }

                yield return fileSet; 
            }
        }

    }
}
